package com.acwing.partition13;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2022/2/27 9:24
 */
public class AC1228油漆面积 {

    private static final int N = 10010;
    private static Segment[] seg = new Segment[N << 1];
    private static Node[] tr = new Node[N << 2];
    private static int n, m;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = Integer.parseInt(reader.readLine());
        for (int i = 0; i < n; i++) {
            String[] ss = reader.readLine().split(" ");
            int x1 = Integer.parseInt(ss[0]), y1 = Integer.parseInt(ss[1]), x2 = Integer.parseInt(ss[2]), y2 = Integer.parseInt(ss[3]);
            seg[m++] = new Segment(x1, y1, y2, 1);
            seg[m++] = new Segment(x2, y1, y2, -1);
        }
        //对线段按照横坐标进行排序，便于后续计算x轴方向的长度
        Arrays.sort(seg, 0, m);
        build(1, 0, N - 1);
        int ans = 0;
        for (int i = 0; i < m; i++) {
            if (i > 0) ans += tr[1].len * (seg[i].x - seg[i - 1].x);
            modify(1, seg[i].y1, seg[i].y2 - 1, seg[i].k);
        }
        writer.write(ans + "\n");
        writer.flush();
    }

    private static void modify(int u, int l, int r, int k) {
        if (l <= tr[u].l && r >= tr[u].r) {
            tr[u].cnt += k;
        } else {
            int mid = tr[u].l + tr[u].r >> 1;
            if (l <= mid) modify(u << 1, l, r, k);
            if (r > mid) modify(u << 1 | 1, l, r, k);
        }
        pushup(u);
    }

    private static void build(int u, int l, int r) {
        tr[u] = new Node(l, r);
        if (l != r) {
            int mid = l + r >> 1;
            build(u << 1, l, mid);
            build(u << 1 | 1, mid + 1, r);
            pushup(u);
        }
    }

    private static void pushup(int u) {
        if (tr[u].cnt > 0) tr[u].len = tr[u].r - tr[u].l + 1;
        else if (tr[u].l == tr[u].r) tr[u].len = 0;
        else tr[u].len = tr[u << 1].len + tr[u << 1 | 1].len;
    }

    private static class Segment implements Comparable<Segment> {
        private int x, y1, y2, k;

        public Segment(int x, int y1, int y2, int k) {
            this.x = x;
            this.y1 = y1;
            this.y2 = y2;
            this.k = k;
        }

        @Override
        public int compareTo(Segment o) {
            return Integer.compare(x, o.x);
        }
    }

    private static class Node {
        //cnt表示当前区间被覆盖的次数，len表示当前区间范围内至少被覆盖一次的长度
        private int l, r, cnt, len;

        public Node(int l, int r) {
            this.l = l;
            this.r = r;
        }
    }
}
